package com.xsm.adapter;

import java.util.ArrayList;

import com.xsm.activitygroup.R;

import android.R.integer;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter{
Context context;
int icons[];
ArrayList<String> texts;
LayoutInflater inflater;
ViewHolder holder;
public MyAdapter(Context context,int icons[],ArrayList<String> texts){
	this.context=context;
	this.icons=icons;
	this.texts=texts;
	inflater=LayoutInflater.from(context);
}
	public int getCount() {
		return texts.size();
	}

	public Object getItem(int arg0) {
		return texts.get(arg0);
	}

	public long getItemId(int arg0){
		return arg0;
	}

	public View getView(int arg0, View arg1, ViewGroup arg2) {
	holder=new ViewHolder();
    if(arg1==null){
    	arg1=inflater.inflate(R.layout.myitem, null);
	holder.icons=(ImageView)arg1.findViewById(R.id.icon);
	holder.text=(TextView)arg1.findViewById(R.id.text);
	holder.to=(ImageView)arg1.findViewById(R.id.to);
	arg1.setTag(holder);
    }else {
		holder=(ViewHolder)arg1.getTag();
	}
    if(icons!=null)
    holder.icons.setBackgroundResource(icons[arg0]);
    else {
    	  holder.icons.setVisibility(View.GONE);	
	}
    holder.text.setText(texts.get(arg0));
    holder.to.setBackgroundResource(R.drawable.to);
		return arg1;
	}
	
class ViewHolder {
	ImageView icons;
	TextView text;
	ImageView to;
}
}
